package com.oolee.cloud;

import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
import org.springframework.context.annotation.Bean;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @author oolee
 * @date 2020/8/18 7:27
 * @apiNote
 * @version 1.0
 */

@SpringBootApplication
@EnableHystrixDashboard
public class DashBoard9001 {

    @Resource
    CachingConnectionFactory rabbitConnectionFactory;

    public static void main(String[] args) {
        SpringApplication.run(DashBoard9001.class,args);

    }

    @Bean
    public ServletRegistrationBean getServlet(){
        HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet();
        ServletRegistrationBean registrationBean = new ServletRegistrationBean(streamServlet);
        registrationBean.setLoadOnStartup(1);
        registrationBean.addUrlMappings("/hystrix.stream");
        registrationBean.setName("HystrixMetricsStreamServlet");
        return registrationBean;
    }


    /*public void test() throws IOException, TimeoutException {
        ConnectionFactory rabbitConnectionFactory = this.rabbitConnectionFactory.getRabbitConnectionFactory();
        Connection connection = rabbitConnectionFactory.newConnection();
        Channel channel = connection.createChannel();
        channel.queueDeclare();


    }*/



}
